﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Data;
using ScrumTable.DL.Data.Schema;

#endregion

namespace ScrumTable.DL.Data.Generic.Cache
{
    /// <summary>
    /// This class provides the base interface for an element list.
    /// </summary>
    public interface ICacheElementList : IEnumerable
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Tries to retrieve the element with the given id.
        /// </summary>
        /// <param name="uniqueId">Id of the element to retrieve.</param>
        /// <returns>Returns an instance or a null reference if the value could not be retrieved.</returns>
        object TryGetById(string uniqueId);

        /// <summary>
        /// Tries to retrieve the element with the given id.
        /// </summary>
        /// <param name="uniqueId">Id of the element to retrieve.</param>
        /// <returns>Returns an instance or a null reference if the value could not be retrieved.</returns>
        T TryGetById<T>(string uniqueId) where T : class, ICacheElement;

        #endregion
    }


    /// <summary>
    /// This class provides the base interface for an element list.
    /// </summary>
    public interface ICacheElementList<T> : ICacheElementList, IEnumerable<T>
        where T : class, ICacheElement
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets/sets the CacheProject List with the given id.
        /// </summary>
        /// <param name="uniqueId">Id of the element to retrieve or set.</param>
        /// <returns>Returns the retrieved instance.</returns>
        T this[string uniqueId] { get; }

        /// <summary>
        /// Gets the number of elements stored in the list.
        /// </summary>
        int Count { get; }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets a member by its display name.
        /// </summary>
        T TryGetBy(Predicate<T> toCompare);

        /// <summary>
        /// Gets a member by its display name.
        /// </summary>
        T TryGetByWithIndex(Predicate<T> toCompare, out int index);

        /// <summary>
        /// Gets a member by its display name.
        /// </summary>
        T TryGetByName(string name);

        /// <summary>
        /// Gets a member by its id. This procedure call may be
        /// slow in conjunction with large lists.
        /// </summary>
        T TryGetById(int id);

        /// <summary>
        /// Tries to retrieve the element with the given id.
        /// </summary>
        /// <param name="uniqueId">Id of the element to retrieve.</param>
        /// <returns>Returns an instance or a null reference if the value could not be retrieved.</returns>
        int IndexOf(string uniqueId);

        /// <summary>
        /// Tries to retrieve the element with the given id.
        /// </summary>
        /// <param name="uniqueId">Id of the element to retrieve.</param>
        /// <param name="index">Specifies the index of the element to retrieve.</param>
        /// <returns>Returns an instance or a null reference if the value could not be retrieved.</returns>
        T TryGetByIdWithIndex(string uniqueId, out int index);

        /// <summary>
        /// Returns true, if the current list contains an element corresponding to the given element.
        /// </summary>
        /// <param name="toCompare">Specifies the element to check.</param>
        bool Contains(T toCompare);

        /// <summary>
        /// Returns true, if the current list contains a value with the given uniqueId.
        /// </summary>
        /// <param name="uniqueId">Id of the element to check.</param>
        bool Contains(string uniqueId);

        #endregion
    }
}